package io.comiccloud

import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.stream.ActorMaterializer
import io.comiccloud.config.Config
import io.comiccloud.rest.OAuthRoutes
import scalikejdbc.config.DBs

import scala.concurrent.ExecutionContext

object Boot extends App with OAuthRoutes with Config{

  def startApplication(): Unit = {
    implicit val actorSystem: ActorSystem = ActorSystem()
    implicit val executor: ExecutionContext = actorSystem.dispatcher
    implicit val materializer: ActorMaterializer = ActorMaterializer()

    Http().bindAndHandle(routes, httpInterface, httpPort)

  }

  def setUpDatabaseResource(): Unit = {
    DBs.setup()
  }

  setUpDatabaseResource()

  startApplication()

}